#!/usr/bin/env node

//const exp = process.argv[2];
//console.log(process.argv);
//console.log(`${exp} = ${eval(exp)}`)

//var argv = process.argv;
//console.log('arguments number:',argv.length);
//console.log('arguments:',argv);

//var expression = argv[2];
//console.log(expression + '=%d', eval(expression))



const log = console.log,
            arg = process.argv[2];

if(typeof(arg) === 'undefined' ||
        arg === '--help' ||
        arg === '-h') {
            help();

        } else {
            calc();

        }

function help() {
    log('\
        usage: cmd-name [OPTION] [expression]\n\
        evaluate the expression.\n\
        \n\
        Mandatory arguments to long options are mandatory for short options too.\n\
        -h, --help output help information and exit');

}

function calc() {
  try {
        log(`${arg} = ${eval(arg)}`);
          
  } catch(e) {
        console.error(`${arg} 不是合法的数学表达式！`);
          
  }

}

